﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ViCode_LeVi.Data;

namespace ViCode_LeVi.Controls.MessageBoxs
{
    /// <summary>
    /// Interaction logic for Window_Ask_Delete_Question.xaml
    /// </summary>
    public partial class Window_Ask_Delete_Question : Window
    {
        public Window_Ask_Delete_Question()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Window_Ask_Delete_Question_Loaded);
        }
        Step_QuestionAnwserGroup _qas;
        Step_QuestionAnwser _qa;
        Action _actionAfter;
        public Window_Ask_Delete_Question(Step_QuestionAnwserGroup qas, Step_QuestionAnwser qa, Action actionAfter)
        {
            InitializeComponent();
            _qas = qas;
            _qa = qa;
            _actionAfter = actionAfter;
            this.Loaded += new RoutedEventHandler(Window_Ask_Delete_Question_Loaded);
        }

        void Window_Ask_Delete_Question_Loaded(object sender, RoutedEventArgs e)
        {
            Button_Cancel.Focus();
            Button_Cancel.Click += new RoutedEventHandler(Button_Cancel_Click);
            Button_Delete_Question.Click += new RoutedEventHandler(Button_Delete_Question_Click);
            Button_Delete_Both.Click += new RoutedEventHandler(Button_Delete_Both_Click);
            Button_Delete_Answer.Click += new RoutedEventHandler(Button_Delete_Answer_Click);
        }

        void Button_Delete_Both_Click(object sender, RoutedEventArgs e)
        {
            if (_qa != null)
            {
                _qas.QuestionAnswers_Source.Remove(_qa);
                if (_actionAfter != null)
                    _actionAfter();
            }
            this.Close();
        }

        void Button_Delete_Question_Click(object sender, RoutedEventArgs e)
        {
            if (_qa != null)
            {
                _qa.Question = string.Empty;
                if (_actionAfter != null)
                    _actionAfter();
            } 
            this.Close();
        }

        void Button_Delete_Answer_Click(object sender, RoutedEventArgs e)
        {
            if (_qa != null)
            {
                _qa.Answer = string.Empty;
                if (_actionAfter != null)
                    _actionAfter();
            } this.Close();
        }
        void Button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
